home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS4.ZIP / DOSKEYS.TXT < prev    next >
Text File  |  1986-06-28  |  8KB  |  179 lines

  1.               IBM Advanced Function Key Techniques
  2.    (COMPUTE! Magazine January 1986 by Peter F. Nicholson, Jr.)
  3.  
  4.      Anyone who has ever redefined the function keys in an IBM BASIC
  5. program probably has wondered why there's no command to restore the
  6. keys' original definitions when the program ends.  Usually you end up
  7. disabling them or redefining them again to their default values.  But
  8. there is an alternative, and the secret lies within something called
  9. the soft key buffer.  Locating and examining this buffer can yield
  10. some interesting results.
  11.  
  12.      Finding the buffer is easy if you have an IBM PC, XT or PCjr.
  13. It starts at memory location 1619 in the default memory segment.  But
  14. this is not necessarily true if you have an IBM-compatible computer.
  15. Therefore, if you're using a compatible, you should run Program 1.
  16. This program attempts to locate the soft key buffer for you.  When you
  17. find it, you should alter the buffer address (1619) in the IBM programs
  18. before running them on your compatible.  The lines where this address
  19. can be found are indicated in REMark statements within each program.
  20.  
  21.      The soft key buffer is just a section of memory which stores the
  22. definitions for the function keys.  When a key is assigned a different
  23. function, its definition within the buffer is altered. A key definition
  24. can contain up to 15 characters.  If you PEEK into the buffer's memory
  25. locations, you may be surprised to find that each key is assigned not
  26. 15, but 16 positions.  Knowing the number of positions allotted for
  27. each function key makes it easy to save the buffer's contents, and
  28. therefore to preserve the keys' definitions.
  29.  
  30.      Program 2 does this by reading the contents of the buffer into an
  31. array.  Then it assigns new functions to the keys.  Finally, the
  32. program lets you restore the original functions by POKEing the contents
  33. of the array back into the soft key buffer.  You can use this technique
  34. in your own programs to restore the function keys.
  35.  
  36.      If you're wondering why each key is assigned 16 positions in the
  37. buffer when its definition can be only 15 characters long, disabling
  38. the keys will provide the answer.  If you PEEK at the 16 positions
  39. reserved for F1 (originally defined as LIST) and print out the ASCII
  40. values, this is what you'll see:  L I S T 0 0 0 0 0 0 0 0 0 0 0 0
  41. When you disable F1, the buffer is:  0 I S T 0 0 0 0 0 0 0 0 0 0 0 0
  42.  
  43.      This seems to indicate that BASIC marks the end of a function key
  44. definition with a zero.  To prove this, run Program 3.  It demonstrates
  45. that you can restore the function keys after disabling them by merely
  46. saving the first character of each key definition (assuming, of course,
  47. that the keys have been disabled by overwriting only the first
  48. character of the definition).  That's why Program 3 needs to save only
  49. 10 bytes instead of the 160 bytes saved by Program 2.
  50.  
  51.      Knowing that you can restore the disabled function keys by saving
  52. only the first character of each definition may be interesting, but
  53. the difference between 10 and 160 bytes probably is of little concern.
  54. The real power in this knowledge is that you can extend the number of
  55. characters available for a function key's definition by altering the
  56. 16th position in the buffer for that key.  This lets you assign a
  57. longer definition to a function key (at the expense of the following
  58. key, however).
  59.  
  60.      For instance, you may prefer to edit programs in SCREEN 0,0,0 and
  61. WIDTH 80.  Using Program 4, you can set F9 to execute these commands
  62. even though they exceed 15 characters.  F10 becomes useless, since the
  63. size of the soft key buffer hasn't been increased -- just the length
  64. of F9's definition within that buffer.
  65.  
  66.      Program 4 also lets you save the new function key definitions as
  67. a file which can be BLOADed from another program.  If you try this,
  68. don't omit the buffer address (1619) when BLOADing the file, since
  69. there is no way to insure that BASIC's segment will be the same as
  70. when you originally created the file.
  71.  
  72. Program 1:  Buffer Finder for Compatibles
  73.  
  74. 100 DEF SEG:SCREEN 0:WIDTH 80:X=0
  75. 110 CLS:PRINT "MEMORY LOCATION ";:LOCATE ,20
  76. 120 KEY 1,"LIST":A=ASC("L")
  77. 130 IF PEEK(X)=A THEN GOSUB 150 ELSE PRINT X;:LOCATE 1,20
  78. 140 X=X+1:GOTO 130
  79. 150 IF CHR$(PEEK(X+1))<>"I" THEN RETURN
  80. 160 IF CHR$(PEEK(X+2))<>"S" THEN RETURN
  81. 170 IF CHR$(PEEK(X+3))<>"T" THEN RETURN
  82. 180 CLS:PRINT "MEMORY LOCATION ";X
  83. 190 FOR J=1 TO 10:PRINT "F";J;:FOR K=0 TO 15
  84. 200 IF PEEK(X+16*(J-1)+K)>0 THEN PRINT CHR$(PEEK(X+16*(J-1)+K)); ELSE 220
  85. 210 NEXT K
  86. 220 PRINT:NEXT J
  87. 230 BEEP:INPUT "IS THIS IT ";Q$
  88. 240 IF Q$="Y" OR Q$="y" THEN END ELSE X=X+1:CLS:GOTO 110
  89.  
  90. Program 2: Restoring Function Definitions
  91.  
  92. 90 'Lines which use 1619 offset are 140 and 250
  93. 100 SCREEN 0:WIDTH 80:CLS:DEF SEG:OPTION BASE 1
  94. 110 KEY ON:DIM K$(10):FOR X=1 TO 10:K$(X)=STRING$(16,0):NEXT X
  95. 120 'Save function keys
  96. 130 FOR X=1 TO 10:FOR J=0 TO 15
  97. 140 MID$(K$(X),J+1,1)=CHR$(PEEK(1619+16*(X-1)+J))
  98. 150 NEXT J,X
  99. 160 'Redefine function keys with letters (example follows)
  100. 170 FOR X=1 TO 10:KEY X,CHR$(X+64):NEXT X:KEY LIST
  101. 180 PRINT "Function keys are redefined":PRINT "Press any key to restore"
  102. 190 KB$=INKEY$:IF KB$="" THEN 190
  103. 200 'Restore function keys
  104. 210 FOR X=1 TO 10
  105. 220 KEY X,K$(X)
  106. 230 NEXT X:CLS
  107. 240 FOR X=1 TO 10
  108. 250 J=ASC(MID$(K$(X),16,1)):IF J>0 THEN POKE 1619+16*(X-1)+15,J
  109. 260 NEXT X:CLS
  110. 260 KEY LIST
  111.  
  112. Program 3: Restoring Function Definitions
  113.  
  114. 90 'Lines which use 1619 offset are 140 and 220
  115. 100 SCREEN 0:WIDTH 80:CLS:DEF SEG
  116. 110 KEY ON:K$=STRING$(10,0)  'Storage area for function keys
  117. 120 'Save function keys
  118. 130 FOR X=1 TO 10
  119. 140 MID$(K$,X,1)=CHR$(PEEK(1619+16*(X-1)))
  120. 150 NEXT X
  121. 160 'Disable function keys
  122. 170 FOR X=1 TO 10:KEY X,"":NEXT X:KEY LIST
  123. 180 PRINT "Function keys are disabled":PRINT "Press any key to restore"
  124. 190 KB$=INKEY$:IF KB$="" THEN 190
  125. 200 'Restore function keys
  126. 210 FOR X=1 TO 10
  127. 220 POKE 1619+16*(X-1),ASC(MID$(K$,X,1))
  128. 230 NEXT X:CLS
  129. 240 KEY LIST
  130.  
  131. Program 4: Extending Definitions
  132.  
  133. 90 'Lines which use 1619 offset are 180, 290, 390, 440, 470
  134. 100 DEF SEG:STK$=STRING$(128,0):SCR$=STRING$(37,0:RESTORE 110:FOR X=1
  135.     TO 37:READ J:MID$(SCR$,X,1)=CHR$(J):NEXT X:SCR!=PEEK(VARPTR(SCR$)
  136.     +1)+256*PEEK(VARPTR(SCR$)+2)
  137. 110 DATA 85,137,229,139,118,6,41,192,138,4,139,116,1
  138. 120 DATA 1,240,137,196,184,0,6,187,0,7,185,0,2
  139. 130 DATA 186,80,24,85,205,16,92,93,202,2,0
  140. 140 SCREEN 0:WIDTH 80:CLS
  141. 150 T$="Function Key Definition"
  142. 160 LOCATE 2,(40-.5*LEN(T$)):PRINT T$
  143. 170 PRINT:PRINT
  144. 180 X=1:J=1:K=1619
  145. 190 K$=STRING$(160,0):KN$=STRING$(160,0):K=K-1
  146. 200 L=PEEK(J+K)
  147. 210 WHILE L<>0
  148. 220 MID$(K$,J,1)=CHR$(L)
  149. 230 J=J+1:L=PEEK(J+K)
  150. 240 WEND
  151. 250 PRINT "Function Key ";X;": ";MID$(K$,1,J-1)
  152. 260 PRINT:PRINT "Enter new definition or press Enter to leave unchanged"
  153. 270 LINE INPUT Q$:IF LEN(Q$)>0 THEN GOSUB 300:IF ER=1 THEN ER=0:GOTO 250
  154. 280 IF X+FIX(J/16)>9 THEN GOTO 380
  155. 290 X=X+1+FIX(J/16):K=1619+16*(X-1)-1:J=1:CALL SCR!(STK$):LOCATE 5,1:
  156.     GOTO 200
  157. 300 INPUT "Do you want a carriage return (Y/N)?;Q1$
  158. 310 IF Q1$="Y" OR Q1$="y" THEN Q$=Q$+CHR$(13)
  159. 320 IF LEN(Q$)<16 THEN J=LEN(Q$):KEY X,Q$:RETURN
  160. 330 M=1:N=16*(X-1)+1:IF N+LEN(Q$)>160 THEN BEEP:PRINT "Too long":ER=1:
  161.     RETURN
  162. 340 MID$(KN$,N,1)=MID$(Q$,M,1)
  163. 350 M=M+1:N=1+N:IF M<=LEN(Q$) THEN 340
  164. 360 IF LEN(Q$)>J THEN J=LEN(Q$)
  165. 370 RETURN
  166. 380 FOR X=1 TO 10
  167. 390 IF ASC(MID$(KN$,16*(X-1)+1,1))>0 THEN FOR J=16*(X-1)+1TO 16*X:POKE
  168.     1619+J-1,ASC(MID$(KN$,J,1)):NEXT J
  169. 400 NEXT X:CLS:KEY LIST
  170. 410 KB$=INKEY$:IF KB$="" THEN 420 ELSE 410
  171. 420 PRINT:INPUT "Do you want to save function keys as a BLOADable
  172.     file (Y/N)?";q$
  173. 430 IF Q$="Y" OR Q$="y" THEN INPUT "Filename";F$ ELSE END
  174. 440 BSAVE F$,1619,159:PRINT
  175. 450 PRINT "To load your function key file, use these commands:"
  176. 460 PRINT:PRINT
  177. 470 PRINT "DEF SEG:BLOAD ";CHR$(34);F$;CHR$(34);",1619:CLS":END
  178.  
  179.